//
// Created by Yun on 2025/2/25.
//

#include "user_bsp_declare.h"
//
// Created by Yun on 2025/2/12.
//

Gpio_Hw_Cfg_TypeDef stGpio_PC5 = {
        .Gpio_x     = GPIOC,
        .stGpioInit= {
                .Pin        = GPIO_PIN_5,
                .Mode       = GPIO_MODE_OUTPUT_PP,
                .Pull       = GPIO_PULLUP,
                .Speed      = GPIO_SPEED_FREQ_LOW
        }
};

Gpio_Hw_Cfg_TypeDef stGpio_PB2 = {
        .Gpio_x     = GPIOB,
        .stGpioInit= {
                .Pin        = GPIO_PIN_2,
                .Mode       = GPIO_MODE_OUTPUT_PP,
                .Pull       = GPIO_PULLUP,
                .Speed      = GPIO_SPEED_FREQ_LOW
        }
};

Gpio_Hw_Cfg_TypeDef stGpio_PA0 = {
        .Gpio_x     = GPIOA,
        .stGpioInit = {
                .Pin        = GPIO_PIN_0,
                .Mode       = GPIO_MODE_INPUT,
                .Pull       = GPIO_PULLDOWN,
                .Speed      = GPIO_SPEED_FREQ_LOW
        }
};

Gpio_Hw_Cfg_TypeDef stGpio_PA1 = {
        .Gpio_x     = GPIOA,
        .stGpioInit = {
                .Pin        = GPIO_PIN_1,
                .Mode       = GPIO_MODE_INPUT,
                .Pull       = GPIO_PULLUP,
                .Speed      = GPIO_SPEED_FREQ_LOW
        }
};

Gpio_Hw_Cfg_TypeDef stGpio_PA4 = {
        .Gpio_x     = GPIOA,
        .stGpioInit = {
                .Pin        = GPIO_PIN_4,
                .Mode       = GPIO_MODE_INPUT,
                .Pull       = GPIO_PULLUP,
                .Speed      = GPIO_SPEED_FREQ_LOW
        }
};

Spi_Hw_Cfg_TypeDef stSpi_SPI1 = {
        .stCLK      = {
                .Gpio_x     = GPIOA,
                .stGpioInit = {
                        .Pin        = GPIO_PIN_5,
                        .Mode       = GPIO_MODE_AF_PP,
                        .Pull       = GPIO_NOPULL,
                        .Speed      = GPIO_SPEED_FREQ_LOW
                }
        },
        .stMOSI     = {
                .Gpio_x     = GPIOA,
                .stGpioInit = {
                        .Pin        = GPIO_PIN_6,
                        .Mode       = GPIO_MODE_AF_PP,
                        .Pull       = GPIO_NOPULL,
                        .Speed      = GPIO_SPEED_FREQ_LOW
                }
        },
        .stMISO     = {
                .Gpio_x     = GPIOA,
                .stGpioInit = {
                        .Pin        = GPIO_PIN_7,
                        .Mode       = GPIO_MODE_AF_PP,
                        .Pull       = GPIO_NOPULL,
                        .Speed      = GPIO_SPEED_FREQ_LOW
                }
        },
        .stCS      = {
                .Gpio_x     = GPIOC,
                .stGpioInit = {
                        .Pin        = GPIO_PIN_13,
                        .Mode       = GPIO_MODE_OUTPUT_PP,
                        .Pull       = GPIO_PULLUP,
                        .Speed      = GPIO_SPEED_FREQ_LOW
                }
        },
        .stHSpi     = {
                .Instance   = SPI1,
                .Init       = {
                        .Mode       = SPI_MODE_MASTER,
                        .Direction  = SPI_DIRECTION_2LINES,
                        .DataSize   = SPI_DATASIZE_8BIT,
                        .CLKPolarity= SPI_POLARITY_HIGH,
                        .CLKPhase   = SPI_PHASE_2EDGE,
                        .NSS        = SPI_NSS_SOFT,
                        .BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8,
                        .FirstBit   = SPI_FIRSTBIT_MSB,
                        .TIMode     = SPI_TIMODE_DISABLE,
                        .CRCCalculation = SPI_CRCCALCULATION_DISABLE,
                        .CRCPolynomial = 7,
                }
        }
};


Uart_Hw_Cfg_TypeDef stUart_UART1 = {
        .stHUart    = {
                .Instance   = USART1,
                .Init       = {
                        .BaudRate   = 115200,
                        .WordLength = UART_WORDLENGTH_8B,
                        .StopBits   = UART_STOPBITS_1,
                        .Parity     = UART_PARITY_NONE,
                        .Mode       = UART_MODE_TX_RX,
                        .HwFlowCtl  = UART_HWCONTROL_NONE,
                        .OverSampling = UART_OVERSAMPLING_16,
                },
        },
        .stTx       = {
                .Gpio_x     = GPIOA,
                .stGpioInit = {
                        .Pin        = GPIO_PIN_9,
                        .Mode       = GPIO_MODE_AF_PP,
                        .Pull       = GPIO_NOPULL,
                        .Speed      = GPIO_SPEED_FREQ_LOW
                }
        },
        .stRx       = {
                .Gpio_x     = GPIOA,
                .stGpioInit = {
                        .Pin        = GPIO_PIN_10,
                        .Mode       = GPIO_MODE_INPUT,
                        .Pull       = GPIO_PULLUP,
                        .Speed      = GPIO_SPEED_FREQ_LOW
                }
        },

        .u8ITPriority = 5,
        .u8ITSubPriority = 0,
};

Tim_Hw_Cfg_TypeDef stTim_TIM6 = {
        .stHTim = {
                .Instance = TIM6,
                .Init = {
                        .Prescaler = 800 - 1,
                        .CounterMode = TIM_COUNTERMODE_UP,
                        .Period = 100 - 1,
                        .ClockDivision = TIM_CLOCKDIVISION_DIV1,
                        .RepetitionCounter = 0,
                }
        },
        .u8ITPriority = 5,
        .u8ITSubPriority = 0,
};

I2C_Hw_Cfg_TypeDef stI2c_I2C1 ={
        .stHI2C = {
               .Instance = I2C1,
               .Init = {
                       .ClockSpeed = 400000,
                       .DutyCycle = I2C_DUTYCYCLE_2,
                       .OwnAddress1 = 0,
                       .AddressingMode = I2C_ADDRESSINGMODE_7BIT,
                       .DualAddressMode = I2C_DUALADDRESS_DISABLE,
                       .OwnAddress2 = 0,
                       .GeneralCallMode = I2C_GENERALCALL_DISABLE,
                       .NoStretchMode = I2C_NOSTRETCH_DISABLE,
                },
        },
       .stSCL = {
               .Gpio_x = GPIOB,
               .stGpioInit = {
                       .Pin = GPIO_PIN_6,    // SCL pin
                       .Mode = GPIO_MODE_AF_OD,
                       .Pull = GPIO_NOPULL,
                       .Speed = GPIO_SPEED_FREQ_HIGH,
               }
        },
       .stSDA = {
               .Gpio_x = GPIOB,
               .stGpioInit = {
                       .Pin = GPIO_PIN_7,    // SDA pin
                       .Mode = GPIO_MODE_AF_OD,
                       .Pull = GPIO_NOPULL,
                       .Speed = GPIO_SPEED_FREQ_HIGH,
               }
        },
};
